package com.scs.application.modules.wm.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.sys.model.RestResult;
import com.scs.application.modules.wm.dto.WorkOrderDTO;
import com.scs.application.modules.wm.entity.WorkOrderItem;
import com.scs.application.modules.wm.service.OutOrderItemService;
import com.scs.application.modules.wm.utils.ServiceState;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 出库单明细 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/wm/out_order_item")
public class OutOrderItemController extends CrudController<OutOrderItemService, WorkOrderItem> {
    /**
     * 扫码
     */
    @PostMapping("/scan")
    public RestResult addByScan(@RequestBody @Valid WorkOrderDTO workOrderDTO) {
        Map<String, Object> resultMap = service.addByScan(workOrderDTO.getWorkOrderId(), workOrderDTO.getUniqueCode());
        // 添加自定义提示
        if (ServiceState.getString(ServiceState.VALID_MSG) != null) {
            return RestResult.ok(ServiceState.getString(ServiceState.VALID_MSG));
        }
        return RestResult.ok("添加成功", resultMap);
    }

    /**
     * 批量选择
     */
    @PostMapping("/addBySelect")
    synchronized public RestResult addBySelect(@RequestBody Map<String, Object> map ) {
        Map<String, Object> resultMap = service.addBySelect(map);
        // 添加自定义提示
        if (ServiceState.getString(ServiceState.VALID_MSG) != null) {
            return RestResult.ok(ServiceState.getString(ServiceState.VALID_MSG));
        }
        return RestResult.ok("添加成功", resultMap);
    }
}
